<?php

namespace app\api\model;
use think\Model;

class Banner extends Model
{
    protected $table='cx_banner';
    protected $pk='id';
    /**
     * 初始化
     */
    protected function initialize()
    {
        //需要调用`Model`的`initialize`方法
        parent::initialize();
        //TODO:自定义的初始化
    }

    /**
     * @return false|\PDOStatement|string|\think\Collection
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * banner列表
     */
    public function index()
    {
        $result = $this->where(array('status' => 1))->field('id,title,picture,url,sort')->order('sort')->select();
        return $result;
    }

    public function getAttr($name)
    {
        $value = $this->getData($name);
        if(in_array($name, ['picture'])) {
            if(strstr($value,'hqrw-cdn')) {
                $value = str_replace('hqrw-cdn.xiaocx.org', 'hqimg.madridwine.cn', $value);
            }
            return $value.'?imageslim';
        }
        return $value;
    }



}